<?php
namespace app\miniprogram\controller;

/**
 * 产品
 */
class Product extends Base
{
    protected $hidden = ['odr'];
    protected $noNeedLogin = ['list', 'look_all'];
	protected $process = ['ProductInfo'];

	//公开产品列表
	public function list() {
		$post = $this->request->param();
		$this->ajax_process(function($process, $user) use ($post) {
            return $process->list();
        });
	}

	//显示店铺产品列表
	public function private_list() {
		$this->ajax_process(function($process, $user) {
            return $process->private_list($user);
        });
	}

	//公开查看基础产品信息
	public function look() {
		$this->ajax_process(function($process, $user) {
            return $process->look();
        });
	}

	//公开查看产品全部信息
	public function look_all() {
		$this->ajax_process(function($process, $user) {
            return $process->look_all();
        });
	}

	//私有查看产品基础信息
	public function info() {
		$this->ajax_process(function($process, $user) {
            return $process->info($user);
        });
	}

	//私有查看产品全部信息
	public function preview_look() {
		$args = $this->ajax_process(function($process, $user) {
            return $process->preview_look($user);
        }, $this->process, true);
        $args['row']->setPhotoFile(true);
        $args['row'] = $args['row']->append(['specs_list']);
        $this->success('', $args);
	}

	//上线产品
	public function show() {
		$this->ajax_process(function($process, $user) {
            return $process->show($user);
        });
	}

	//下线产品
	public function hide() {
		$this->ajax_process(function($process, $user) {
            return $process->hide($user);
        });
	}

	//获取产品审核记录
	public function examine_log() {
		$this->ajax_process(function($process, $user) {
            return $process->private_list($user, function($model){
            	$model->append(['examine_log', 'specs_list']);
            });
        });
	}

	//获取产品被拒绝信息
	public function remark() {
		$pid = $this->request->param('id');
		$to  = $this->request->post('to', -1);
		$user = $this->get_login()->getCurrentUser();
		$post = ['pid' => $pid, 'to' => $to, 'uid' => $user['id']];

		$validate = loadValidate('tysj\\ProductExamineLog');
		if(!$validate->scene('new')->check($post)){
			$this->error($validate->getError());
		}
		$data = loadModel('tysj\\ProductExamineLog')->where(['pid' => $post['pid'], 'to' => $post['to']])->field('remark,createtime')->find();
		$this->success('', $data);
	}

	//保存
    public function save() {
    	$this->ajax_process(function($process, $user) {
            return $process->save($user);
        });
    }

    //删除产品
    public function del() {
    	$this->ajax_process(function($process, $user) {
            return $process->delAll($user);
        });
    }
}
